#!/bin/bash

#定义变量
## 分区的硬盘,注意是全盘分成一个区,否则不要定义此变量
disk='/dev/sda'

#分区格式化,掛載
echo -e "$disk is initing"
fdisk $disk &>fdisk_sdb.log <<EOF
n
p
 


w
EOF
echo -e "$disk is finish"

partprobe
mkfs -t ext4 ${disk}1
mkdir -p /mnt
mount ${disk}1 /mnt

#修改成中国的源,加速
mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
cat > /etc/pacman.d/mirrorlist << EOF
#清华大学源
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/\$repo/os/\$arch
#阿里源
Server = http://mirrors.aliyun.com/archlinux/\$repo/os/\$arch
#华为源
Server = https://mirrors.huaweicloud.com/archlinux/\$repo/os/\$arch
EOF

#安装基本系统
echo "install bash-completion base base-devel linux vim grub openssh networkmanager"
pacstrap /mnt bash-completion base base-devel linux vim grub openssh networkmanager
##配置系统
###生成vim配置文件
cat > /mnt/root/.vimrc << EOF
set mouse-=a
syntax on
set hlsearch
set incsearch
EOF
echo "alias vi='vim'" >> /mnt/root/.bashrc
###生成fstab文件
genfstab -U /mnt >> /mnt/etc/fstab
#复制脚本到新系统的root目录
cp /root/{script2.sh,script3.sh} /mnt/root
#复制源到新系统的目录
mv /mnt/etc/pacman.d/mirrorlist /mnt/etc/pacman.d/mirrorlist.bak
cp /etc/pacman.d/mirrorlist /mnt/etc/pacman.d/mirrorlist
###切换到新安装的系统
echo "切换根"
arch-chroot /mnt
